package com.alenus.redis.controller;

import com.alenus.redis.domain.Department;
import com.alenus.redis.service.DepartmentService;
import com.alenus.redis.util.Jedis.JedisClustorClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by pactera on 2018/10/15.
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    public DepartmentService departmentService;

    @Autowired
    public JedisClustorClient jedisClustorClient;


    @RequestMapping("/getDepartment/{id}")
    public Department getDepartment(@PathVariable("id") int id) {

        Department department = departmentService.queryObject(id);
        jedisClustorClient.setObject("department" + id, department, 1000000000);
        return department;
    }

    @RequestMapping("/getRedisDepartment/{id}")
    public String getRedisDepartment(@PathVariable("id") int id) {
        String result = jedisClustorClient.getObject("department" + id);
        return result;
    }

}
